Jenkins 在通过 Git 插件(Remote Repo Bitbucket)拉取子模块时报告权限失败

Jenkins Reports Permission Failure When Pulling Submodule via Git Plugin (Remote Repo Bitbucket)

我在 Bitbucket(云)中有一个项目,我正在使用 Jenkins(在本地托管)构建该项目。该项目有一个子模块。如果我忽略子模块,作业(在 Jenkins 中)就会成功。如果我尝试更新子模块,我会收到这条情书:

stderr: Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

下面是我的 SCM 配置的完整作业日志以供参考。

我们在 Bitbucket 中使用应用程序密码来访问存储库。

我尝试过的东西...

  1. 将 Git 插件更新到 v4.1.1 - 根据 Jenkins 管道 git 命令子模块更新
  2. 创建了一个单独的作业来使用相同的凭据提取子模块的存储库。我能够使用与有问题的工作相同的凭据从 Jenkins 中提取 repo,没有问题。
  3. 子模块在lambda/messages目录中;没错

我项目的 .gitmodules 文件的内容...

[submodule "lambda/messages"]
        path = lambda/messages
        url = git@bitbucket.org:myCompany/myRespository.git

Jenkins 作业的输出...

Started by user myUser
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\Started by user myUser
Running as SYSTEM
Building in workspace C:\Program Files (x86)\Jenkins\workspace\myRespository
using credential Bitbucket
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://myUser@bitbucket.org/myCompany/deco4-aws.git # timeout=10
Fetching upstream changes from https://myUser@bitbucket.org/myCompany/deco4-aws.git
> git.exe --version # timeout=10
using GIT_ASKPASS to set credentials Bitbucket App password for Jenkins
> git.exe fetch --tags --progress -- https://myUser@bitbucket.org/myCompany/deco4-aws.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision cecc872074937f981a9c593b931440b320b2ea32 (refs/remotes/origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f cecc872074937f981a9c593b931440b320b2ea32 # timeout=10
Commit message: "PS-2315: added thing vars/api/lambda"
> git.exe rev-list --no-walk cecc872074937f981a9c593b931440b320b2ea32 # timeout=10
> git.exe remote # timeout=10
> git.exe submodule init # timeout=10
> git.exe submodule sync # timeout=10
> git.exe config --get remote.origin.url # timeout=10
> git.exe submodule init # timeout=10
> git.exe config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
> git.exe config --get submodule.lambda/messages.url # timeout=10
> git.exe remote # timeout=10
> git.exe config --get remote.origin.url # timeout=10
> git.exe config -f .gitmodules --get submodule.lambda/messages.path # timeout=10
using GIT_ASKPASS to set credentials Bitbucket App password for Jenkins
> git.exe submodule update --init --recursive lambda/messages # timeout=10
hudson.plugins.git.GitException: Command "git.exe submodule update --init --recursive lambda/messages" returned status code 1:
stdout: 
stderr: Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:myCompany/deco4-messaging.git' into submodule path 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages' failed
Failed to clone 'lambda/messages'. Retry scheduled
Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:myCompany/deco4-messaging.git' into submodule path 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages' failed
Failed to clone 'lambda/messages' a second time, aborting
using credential Bitbucket
> git.exe rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
> git.exe config remote.origin.url https://myUser@bitbucket.org/myCompany/deco4-aws.git # timeout=10
Fetching upstream changes from https://myUser@bitbucket.org/myCompany/deco4-aws.git
> git.exe --version # timeout=10
using GIT_ASKPASS to set credentials Bitbucket App password for Jenkins
> git.exe fetch --tags --progress -- https://myUser@bitbucket.org/myCompany/deco4-aws.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10
> git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10
Checking out Revision cecc872074937f981a9c593b931440b320b2ea32 (refs/remotes/origin/master)
> git.exe config core.sparsecheckout # timeout=10
> git.exe checkout -f cecc872074937f981a9c593b931440b320b2ea32 # timeout=10
Commit message: "PS-3176: added more things vars/api/lambda"
> git.exe rev-list --no-walk cecc872074937f981a9c593b931440b320b2ea32 # timeout=10
> git.exe remote # timeout=10
> git.exe submodule init # timeout=10
> git.exe submodule sync # timeout=10
> git.exe config --get remote.origin.url # timeout=10
> git.exe submodule init # timeout=10
> git.exe config -f .gitmodules --get-regexp ^submodule\.(.+)\.url # timeout=10
> git.exe config --get submodule.lambda/messages.url # timeout=10
> git.exe remote # timeout=10
> git.exe config --get remote.origin.url # timeout=10
> git.exe config -f .gitmodules --get submodule.lambda/messages.path # timeout=10
using GIT_ASKPASS to set credentials Bitbucket App password for Jenkins
> git.exe submodule update --init --recursive lambda/messages # timeout=10
hudson.plugins.git.GitException: Command "git.exe submodule update --init --recursive lambda/messages" returned status code 1:
stdout: 
stderr: Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:myCompany/deco4-messaging.git' into submodule path 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages' failed
Failed to clone 'lambda/messages'. Retry scheduled
Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@bitbucket.org:myCompany/deco4-messaging.git' into submodule path 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages' failed
Failed to clone 'lambda/messages' a second time, aborting

Jenkins 作业的 SCM 配置...

运行 没有关于根本原因的想法。任何指导表示赞赏。

正在通过 SSH 访问子模块,而父模块是 HTTPS。

子模块...

[submodule "lambda/messages"]
        path = lambda/messages
        url = git@bitbucket.org:myCompany/myRespository.git

父仓库...

由于我没有设置任何 SSH 密钥,Jenkins 可以在克隆子模块时进行身份验证。而且,现在错误是有道理的:

stderr: Cloning into 'C:/Program Files (x86)/Jenkins/workspace/my.repository/lambda/messages'...
git@bitbucket.org: Permission denied (publickey).
fatal: Could not read from remote repository.

为了修复,我重新配置了存储库中的子模块以通过 https 访问它的远程存储库。更改是通过编辑存储库根目录中的 ./.gitmodules 文件进行的。

[submodule "lambda/messages"]
    path = lambda/messages
    url = https://myUser@bitbucket.org/myCompany/myRepository.git

下一次构建如期成功。

希望这对某人有所帮助!